<%@page import="br.com.fatecpg.ads.poo.projeto.conexao.OracleConnector"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/javascript" href="../_res/js/bootstrap.js">
        <link rel="stylesheet" type="text/css" href="../_res/css/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="../_res/css/bootstrap-theme.css">
        <link rel="stylesheet" type="text/css" href="../_res/css/bootstrap.min.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <%@include file="../_templates/menu.jsp" %>
        <div style="padding-left: 13em;">
            <h2>Confirmação</h2>
            <%
            if (request.getParameter("usuario") != null
                    && request.getParameter("senha") != null
                    && request.getParameter("email") != null){
                String usuario = request.getParameter("usuario");
                String senha = request.getParameter("senha");
                String email = request.getParameter("email");
                String bar = "N";
                
                if (request.getParameter("opcao").equals("rbar"))
                    bar = "S";
                
                String SQL = "INSERT INTO usuario (id_usuario, nm_usuario, nm_senha, nm_email, ic_bar) "
                        + " VALUES ("
                        + " (SELECT NVL(MAX(id_usuario),0) FROM USUARIO) + 1, "
                        + " '"+usuario+"', "
                        + " '"+senha+"', "
                        + " '"+email+"', "
                        + " '"+bar+"') ";
                
                int sucess = OracleConnector.executeStatement(SQL);
                
                if (sucess == 1){
                    out.println("<h3>Cadastrado com sucesso!</h3>");
                    response.sendRedirect("home.jsp");
                } else {
                    out.println("<h3>Erro ao cadastrar</h3>");
                }
                        
            }
            %>
        </div>
        <%@include file="../_templates/footer.jsp"%>
    </body>
</html>
